﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Mvc;
using webcspa.Models;

namespace webcspa.Controllers
{
    //google: execute stored procedure c sharp
    public class DataController : Controller
    {
        private const string connectionString = "Data Source=GORBUNOV-MS\\GORBUNOV;Initial Catalog=CSPA;Persist Security Info=True;User ID=sa;Password=vbif0192837465";

        public ActionResult Run()
        {
            var result = new List<TestModel>();

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = "select * from cls_ktr";
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    var item = new TestModel
                                   {
                                       TYPE_ID = reader.GetInt32(0),
                                       NUM_RPN = reader.GetInt32(1),
                                       KTR = reader.GetDouble(2),
                                   };
                    result.Add(item);
                }
            }
            return View("View", result.ToArray());
        }

    }
}
